package hn.cch.mybatis.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;

/**
 * 实现Spring加载Mapper注解
 */
public class MapperApplication {

    private static final Logger logger = LoggerFactory.getLogger(MapperApplication.class);


    public static void main(String[] args) {
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.registerBean("springMyBatisConfiguration", MapperConfiguration.class);
        // @ComponentScan @Bean @Import @ImportResource
        applicationContext.registerBean(ConfigurationClassPostProcessor.class);

        // 实现过程
        applicationContext.registerBean(MapperPostProcessor.class); // @Mapper

        applicationContext.refresh();
        for (String name : applicationContext.getBeanDefinitionNames()) {
            logger.info("Mapper:{}", name);
        }
        applicationContext.close();
    }


}
